package com.icehand.payment.pay.wechat;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;
import com.icehand.payment.pay.SignGenerator;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * @author icehand
 * create on 2018-06-15
 **/
@Data
@Accessors(chain = true)
public class WeChatPaymentUnifiedOrderRequest implements SignGenerator {
	/**
	 * 	necessary
	 */

	@JSONField(name = "appid")
	private String appid;

	@JSONField(name = "mch_id")
	private String mch_id;

	@JSONField(name = "nonce_str")
	private String nonce_str;

	@JSONField(name = "body")
	private String body;

	@JSONField(name = "out_trade_no")
	private String out_trade_no;

	/**
	 * 金额为分
	 */
	@JSONField(name = "total_fee")
	private String total_fee;

	@JSONField(name = "spbill_create_ip")
	private String spbill_create_ip;

	@JSONField(name = "notify_url")
	private String notify_url;

	@JSONField(name = "trade_type")
	private String trade_type = "APP";

	@JSONField(name = "sign")
	private String sign;

	@JSONField(name = "fee_type")
	private String fee_type;

	@JSONField(name = "sign_type")
	private String sign_type;

	@JSONField(name = "openid")
	private String openid;

	//------------------------un
	/**
	 * 订单开始时间 20091227091010
	 */
	@JSONField(name = "time_start")
	private String time_start;

	/**
	 * 订单失效时间 20091227091010
	 */
	@JSONField(name = "time_expire")
	private String time_expire;


	/**
	 * 商品详情
	 */
	private String detail;

	/**
	 * 附加数据
	 */
	private String attach;

	/**
	 * 终端设备号(门店号或收银设备ID)
	 */
	@JSONField(name = "device_info")
	private String device_info;

	/**
	 * 订单优惠标记，代金券或立减优惠功能的参数
	 */
	@JSONField(name = "goods_tag")
	private String goods_tag;

	/**
	 * 指定支付方式
	 */
	@JSONField(name = "limit_pay")
	private String limit_pay;

	/**
	 * 该字段用于统一下单时上报场景信息
	 */
	@JSONField(name = "scene_info")
	private String scene_info;

	@Override
	public void createSign(String secret) {
		Map<String,String> map = JSONObject.parseObject(JSON.toJSONString(this),new TypeReference<Map<String, String>>(){});
		this.sign = WeChatPaymentSignatureUtils.generateSignature(map, secret);
	}
}
